package cn.easier.activity.console.configration;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;

@Configuration
public class ActivityWebMvcConfiguration extends WebMvcConfigurerAdapter {

    /**
     * 静态资源映射
     */
    private static final String STATIC_RESOURCE_LOCATION = "/staticResources/**";

    /**
     * 项目内部资源映射
     */
    private static final String PROJECT_INSIDE_RESOURCE_LOCATION = "/**";

    /**
     * 项目内部资源路径
     */
    private static final String PROJECT_INSIDE_RESOURCE_PATH = "classpath:/static/dist/";

    @Resource
    private ActivityConsoleConfiguration activityConsoleConfiguration;

    /**
     * 资源映射器
     * */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(STATIC_RESOURCE_LOCATION).addResourceLocations("file:".concat(this
                .activityConsoleConfiguration.realPath));
        registry.addResourceHandler(PROJECT_INSIDE_RESOURCE_LOCATION).addResourceLocations(PROJECT_INSIDE_RESOURCE_PATH);
        super.addResourceHandlers(registry);
    }

    /**
     * 首页配置
     * */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:".concat("home"));
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }
}
